<?php

namespace App\Http\Controllers\H5;

use App\Services\ErrorCodeService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

class H5BaseController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    //全局参数
    protected $_param = [];

    /**
     * Controller constructor.
     */
    public function __construct(Request $request)
    {

    }

    /**
     * 统一成功返回
     * @param array $data
     * @param int $code
     * @param string $message
     * @return object|null
     */
    public static function codeSuccess(array $data = [], int $code = 200, string $message = '操作成功'): ?object
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data
        ]);
    }

    /**
     * 统一成功返回
     * @param array $data
     * @param int $code
     * @param string $message
     * @return object|null
     */
    public static function codeError(array $data = [], int $code = 1001, string $message = '操作失败'): ?object
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data
        ]);
    }

}
